Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Memory

Previous | Chapter Top | Chapter Contents | Next |

Allocating and Releasing Nonrelocatable Blocks of Memory

You can use the NewPtr function to allocate a nonrelocatable block of memory. If you want to allocate new blocks of memory with their bits precleared to 0, you can use the NewPtrClear function.

You should not call any of these memory-allocation routines at interrupt time.<36pt>

You can use the DisposePtr procedure to free nonrelocatable blocks of memory you have allocated.

NewPtr

You can use the NewPtr function to allocate a nonrelocatable block of memory of a specified size.

FUNCTION NewPtr (logicalSize: Size): Ptr;
logicalSize
The requested size (in bytes) of the nonrelocatable block.

DESCRIPTION

The NewPtr function attempts to allocate, in the current heap zone, a nonrelocatable block with a logical size of logicalSize bytes and then return a pointer to the block. If the requested number of bytes cannot be allocated, NewPtr returns NIL .

The NewPtr function attempts to reserve space as low in the heap zone as possible for the new block. If it is able to reserve the requested amount of space, NewPtr allocates the nonrelocatable block in the gap ReserveMem creates. Otherwise, NewPtr returns NIL and generates a memFullErr error.

SPECIAL CONSIDERATIONS

Because NewPtr allocates memory, you should not call it at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The registers on entry and exit for NewPtr are

Registers on entry

A0

Number of logical bytes requested

Registers on exit

A0

Address of the new block or NIL

D0

Result code

If you want to clear the bytes of a block of memory to 0 when you allocate it with the NewPtr function, set bit 9 of the routine trap word. You can usually do this by supplying the word CLEAR as the second argument to the routine macro, as follows:

_NewPtr ,CLEAR

RESULT CODES

noErr

0

No error

memFullErr

-108

Not enough memory

NewPtrClear

You can use the NewPtrClear function to allocate prezeroed memory in a nonrelocatable block of a specified size.

FUNCTION NewPtrClear (logicalSize: Size): Ptr;
logicalSize
The requested size (in bytes) of the nonrelocatable block.

DESCRIPTION

The NewPtrClear function works much as the NewPtr function does, but sets all bytes in the new block to 0 instead of leaving the contents of the block undefined.

Currently, NewPtrClear clears the block one byte at a time. For a large block, it might be faster to clear the block manually a long word at a time.

RESULT CODES

noErr

0

No error

memFullErr

-108

Not enough memory

DisposePtr

When you are completely done with a nonrelocatable block, call the DisposePtr procedure to free it for other uses.

PROCEDURE DisposePtr (p: Ptr);
p
A pointer to the nonrelocatable block you want to dispose of.

DESCRIPTION

The DisposePtr procedure releases the memory occupied by the nonrelocatable block specified by p .

After a call to DisposePtr , all pointers to the released block become invalid and should not be used again. Any subsequent use of a pointer to the released block might cause a system error.

SPECIAL CONSIDERATIONS

Because DisposePtr purges memory, you should not call it at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The registers on entry and exit for DisposePtr are

Registers on entry

A0

Pointer to the nonrelocatable block to be disposed of

Registers on exit

D0

Result code

RESULT CODES

noErr

0

No error

memWZErr

-111

Attempt to operate on a free block


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next